import requests
import json
from read_search_file import  return_headers
from loguru import logger

url = "https://ad.xiaohongshu.com/api/idea/spu/bind_multi_spu" # 直达链接添加接口

def log_message(log_callback, message, color=None):
    if callable(log_callback):
        log_callback(message, color) if color else log_callback(message)
def collect_direct_link_list_exists(cookies=None, account_id=None, data=None, log_callback=None, note_id=None, spu_id_list=None):

    headers = return_headers(account_id=account_id)
    data = json.dumps(data, separators=(',', ':'))
    response = requests.post(url, headers=headers, cookies=cookies, data=data)

    res_json = response.json()

    if res_json.get('code') == 0:
        log_message(log_callback, f'笔记:{note_id}绑定成功', "green")
    else:
        log_message(log_callback, f'笔记:{note_id}绑定失败', "red")